﻿CREATE PROCEDURE [dbo].[usp_select_AlertByID]
@AlertID uniqueidentifier
AS

SET NOCOUNT ON;

SELECT 
		 [AlertID]
		,[Name]
		,[ConditionsString]
		,[InsertedBy]
		,(SELECT COUNT(AlertID) FROM dbo.AlertSubscription s WHERE AlertID = a.AlertID AND s.Subscriber != a.InsertedBy) AS OwnerSubscriberCount
		,(SELECT COUNT(AlertID) FROM dbo.AlertSubscription s WHERE AlertID = a.AlertID AND s.Subscriber != a.InsertedBy) AS OtherSubscriberCount
		,InsertedDate
FROM 
		[dbo].[Alert] a

WHERE
		[AlertID] = @AlertID


SET NOCOUNT OFF;
